﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    public class DataModelErrorCode
    {

        public const string Error                           = "FASDataModel-Error-1001";
        public const string NullValue                       = "FASDataModel-Error-1002";
        public const string ParamError                      = "FASDataModel-Error-1003";
        public const string DataRowConvertToEntityError     = "FASDataModel-Error-2001";
        public const string ConvertToEnumError              = "FASDataModel-Error-2002";
        public const string ELBFacotryError                 = "FASDataModel-Error-3001";
        public const string MyBatisFacotryError             = "FASDataModel-Error-3002";
        public const string ValidError                      = "FASDataModel-Error-4001";
        public const string AssertError                     = "FASDataModel-Error-4002";
        public const string NeedRepairError                 = "FASDataModel-Error-5001";

        public class CDO
        {
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string InitError = "FASDataModel-CDO-1000";
            /// <summary>
            /// CDO主表保存异常
            /// </summary>
            public const string CreateError = "FASDataModel-CDO-1001";
            public const string RetrieveError = "FASDataModel-CDO-1002";
            public const string UpdateError = "FASDataModel-CDO-1003";
            /// <summary>
            /// CDO主表删除异常
            /// </summary>
            public const string DeleteError = "FASDataModel-CDO-1004";
            public const string ImportError = "FASDataModel-CDO-1005";
            public const string ValidError = "FASDataModel-CDO-1006";
            public const string RepairError = "FASDataModel-CDO-1007";
            public const string GenerateCNOAliasError = "FASDataModel-CDO-1009";
            #region Association
            public const string CreateAssoError = "FASDataModel-CDO-2001";
            public const string DeleteAssoError = "FASDataModel-CDO-2002";
            public const string CreateAssoItemError = "FASDataModel-CDO-2003";
            public const string DeleteAssoItemError = "FASDataModel-CDO-2004";
            public const string CreateAssoRefError = "FASDataModel-CDO-2005";
            public const string DeleteAssoRefError = "FASDataModel-CDO-2006";
            #endregion
            #region CNO
            public const string CreateCNOError = "FASDataModel-CDO-3001";
            public const string DeleteCNOError = "FASDataModel-CDO-3002";
            public const string CreateCNOEleError = "FASDataModel-CDO-3001";
            public const string DeleteCNOEleError = "FASDataModel-CDO-3002";
            #endregion
        }
        public class DB
        {
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string CreateError = "FASDataModel-Database-1001";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string DeleteError = "FASDataModel-Database-1004";
            public const string UniqueCheckError = "FASDataModel-Database-1005";

            public const string CreateCfgError = "FASDataModel-Database-2001";
            public const string DeleteCfgError = "FASDataModel-Database-2002";
            public const string UpdateCfgError = "FASDataModel-Database-2003";
        }
        public class DO
        {
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string InitError = "FASDataModel-DataObject-1000";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string CreateError = "FASDataModel-DataObject-1001";
            public const string RetrieveError = "FASDataModel-DataObject-1002";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string UpdateError = "FASDataModel-DataObject-1003";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string DeleteError = "FASDataModel-DataObject-1004";
            public const string ImportError = "FASDataModel-DataObject-1005";
            public const string ValidError = "FASDataModel-DataObject-1006";
            public const string SyncError = "FASDataModel-DataObject-1010";
            public const string SyncGetDBError = "FASDataModel-DataObject-1011";
            public const string SyncExecuteSQLError = "FASDataModel-DataObject-1012";

            public const string CreateColumnError = "FASDataModel-DataObject-2001";
            public const string DeleteColumnError = "FASDataModel-DataObject-2002";
            public const string UpdateColumnError = "FASDataModel-DataObject-2003";

            public const string CreateRelationError = "FASDataModel-DataObject-3001";
            public const string DeleteRelationError = "FASDataModel-DataObject-3002";
            public const string UpdateRelationError = "FASDataModel-DataObject-3003";

            public const string CreatePresetDataError = "FASDataModel-DataObject-4001";
            public const string DeletePresetDataError = "FASDataModel-DataObject-4002";
            public const string UpdatePresetDataError = "FASDataModel-DataObject-4003";

            public const string CreateIndexError = "FASDataModel-DataObject-5001";
            public const string DeleteIndexError = "FASDataModel-DataObject-5002";
            public const string UpdateIndexError = "FASDataModel-DataObject-5003";

            public const string CreateIndexColumnError = "FASDataModel-DataObject-5011";
            public const string DeleteIndexColumnError = "FASDataModel-DataObject-5012";
            public const string UpdateIndexColumnError = "FASDataModel-DataObject-5013";
        }
        public class DQ
        {
            public const string BuildSchemaError = "FASDataModel-DataQuery-0001";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string InitError = "FASDataModel-DataQuery-1000";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string CreateError = "FASDataModel-DataQuery-1001";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string RetrieveError = "FASDataModel-DataQuery-1002";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string UpdateError = "FASDataModel-DataQuery-1003";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string DeleteError = "FASDataModel-DataQuery-1004";
            public const string ImportError = "FASDataModel-DataQuery-1005";
            public const string RepairError = "FASDataModel-DataQuery-1006";

            public const string CreateFilterError = "FASDataModel-DataQuery-2001";
            public const string DeleteFilterError = "FASDataModel-DataQuery-2002";
            public const string UpdateFilterError = "FASDataModel-DataQuery-2003";

            public const string CreateJoinError = "FASDataModel-DataQuery-3001";
            public const string DeleteJoinError = "FASDataModel-DataQuery-3002";
            public const string UpdateJoinError = "FASDataModel-DataQuery-3003";

            public const string CreateParamError = "FASDataModel-DataQuery-4001";
            public const string DeleteParamError = "FASDataModel-DataQuery-4002";
            public const string UpdateParamError = "FASDataModel-DataQuery-4003";

            public const string CreateSortError = "FASDataModel-DataQuery-5001";
            public const string DeleteSortError = "FASDataModel-DataQuery-5002";
            public const string UpdateSortError = "FASDataModel-DataQuery-5003";

            public const string CreateSourceError = "FASDataModel-DataQuery-6001";
            public const string DeleteSourceError = "FASDataModel-DataQuery-6002";
            public const string UpdateSourceError = "FASDataModel-DataQuery-6003";
        }
        public class EO
        {
            public const string BuildSchemaError = "FASDataModel-EntityObject-0001";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string InitError = "FASDataModel-EntityObject-1000";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string CreateError = "FASDataModel-EntityObject-1001";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string RetrieveError = "FASDataModel-EntityObject-1002";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string UpdateError = "FASDataModel-EntityObject-1003";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string DeleteError = "FASDataModel-EntityObject-1004";
            public const string ImportError = "FASDataModel-EntityObject-1005";

            public const string CreateAttrError = "FASDataModel-EntityObject-2001";
            public const string UpdateAttrError = "FASDataModel-EntityObject-2003";
            public const string DeleteAttrError = "FASDataModel-EntityObject-2004";
        }
        public class SM
        {
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string InitError = "FASDataModel-StateMachine-1000";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string CreateError = "FASDataModel-StateMachine-1001";
            /// <summary>
            /// Database主表保存异常
            /// </summary>
            public const string RetrieveError = "FASDataModel-StateMachine-1002";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string UpdateError = "FASDataModel-StateMachine-1003";
            /// <summary>
            /// Database主表删除异常
            /// </summary>
            public const string DeleteError = "FASDataModel-StateMachine-1004";
            public const string ImportError = "FASDataModel-StateMachine-1005";
            public const string ValidError = "FASDataModel-StateMachine-1006";
            public const string SerializeError = "FASDataModel-StateMachine-1007";


            public const string CreateActionError = "FASDataModel-StateMachine-2001";
            public const string UpdateActionError = "FASDataModel-StateMachine-2003";
            public const string DeleteActionError = "FASDataModel-StateMachine-2004";

            public const string CreateEventError = "FASDataModel-StateMachine-3001";
            public const string UpdateEventError = "FASDataModel-StateMachine-3003";
            public const string DeleteEventError = "FASDataModel-StateMachine-3004";

            public const string CreateRuleError = "FASDataModel-StateMachine-4001";
            public const string RetrieveRuleError = "FASDataModel-StateMachine-4001";
            public const string UpdateRuleError = "FASDataModel-StateMachine-4003";
            public const string DeleteRuleError = "FASDataModel-StateMachine-4004";

            public const string CreateStateError = "FASDataModel-StateMachine-5001";
            public const string UpdateStateError = "FASDataModel-StateMachine-5003";
            public const string DeleteStateError = "FASDataModel-StateMachine-5004";

            public const string CreateTransError = "FASDataModel-StateMachine-6001";
            public const string UpdateTransError = "FASDataModel-StateMachine-6003";
            public const string DeleteTransError = "FASDataModel-StateMachine-6004";
        }

        public class Tool
        {
            public const string Error = "FASDataModel-Tool-1001";
            public const string NullValue = "FASDataModel-Tool-1002";
        }

        public class DataType
        {
            public const string TypeCastError = "FASDataModel-DataType-1001";
            public const string NotSupportedType = "FASDataModel-DataType-1002";
            public const string ForeignKeyError = "FASDataModel-DataType-1003";
            public const string TypeMappingError = "FASDataModel-DataType-1004";
            public const string NullValue = "FASDataModel-DataType-1005";
        }

        public class RTP
        {
            public const string Error = "FASDataModelRTP-Error-1001";
        }

        /// <summary>
        /// 获取可以修复的元数据错误ErroCode前缀
        /// </summary>
        /// <param name="MetaTypeID"></param>
        /// <returns></returns>
        public static string GetNeedRepairErrorCode(string MetaTypeID)
        {
            return $"ErrorCode:{NeedRepairError},MetaTypeID:{MetaTypeID}";
        }

        /// <summary>
        /// 获取统一的错误前缀
        /// </summary>
        /// <param name="MetaTypeID"></param>
        /// <returns></returns>
        public static string GetUnifiedErrorCode(string MetaType, string MetaID, string MetaCode = null)
        {
            return $"元数据类型{MetaType}的元数据ID:{MetaID},Code:{MetaCode}";
        }
    }
}